// mircoApp/lunarCalendar/perpetual/perpetual.js
const { Lunar } = require("../lunar.js");
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgPath: app.globalData.host,
    selectDay: "",
    dayStr: "",
    weekStr: "",
    yearStr: "",
    yi: "",
    ji: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    app._postNetWork({url: app.getNetAddresss('member.login.check-login')});//主要是判断登录和获取底部导航
    let curDate = new Date();
    this.data.selectDay = curDate.getFullYear() + "/" + (curDate.getMonth() + 1) + "/" + curDate.getDate();
    this.render();
  },
  render(setDateStr) {
    let obj = {};
    let dd = setDateStr ? new Date(setDateStr) : new Date(this.data.selectDay);
    let d = Lunar.fromDate(dd);
    obj.dayStr = d.getMonthInChinese() + "月" + d.getDayInChinese();
    obj.yearStr = d.getYearInGanZhi() + "(" + d.getYearShengXiao() + ")年";
    obj.weekStr = "星期" + d.getWeekInChinese();
    obj.ji = d.getDayJi().join(" ");
    obj.yi = d.getDayYi().join(" ");
    this.setData(obj);
  },
  dayChange(e) {
    let data = e.detail;
    this.setData({
      selectDay: data.time
    });
    this.render(data.time);
    console.log("日期选择变更", data);
  },
  monthChange(data) {
    console.log("月份选择变更", data);
  },
  toAlmanac() {
    wx.navigateTo({
      url: `/mircoApp/lunarCalendar/almanac/almanac?data=${this.data.selectDay}`
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})